package com.pcbly.web.components.utils.template.pagemess;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import com.pcbly.web.components.utils.template.TemplateModel;

public abstract class ModelPage {
	public final static String packName = "com.pcbly.web.components.utils.template";

	public TemplateModel model;

	public Field[] fields;
	
	private List<String> messagesString = new ArrayList<String>(); 

	public List<String> getMessagesString() {
		return messagesString;
	}

	public void setMessagesString(List<String> messagesString) {
		this.messagesString = messagesString;
	}

	public TemplateModel getModel() {
		return model;
	}

	public void setModel(TemplateModel model) {
		this.model = model;
	}

	public Field[] getFields() {
		return fields;
	}

	public void setFields(Field[] fields) {
		this.fields = fields;
	}
	
	public void printMessages(){
		messagesString.add("#--- " + model.getFirstEntityL()
				+ " -----------\r\n");
		messagesString.add(model.getFirstEntityL() + ".action="
				+ model.getEntityP() + " Action\r\n");
		messagesString.add(model.getFirstEntityL() + ".modify="
				+ model.getEntityP() + " Modify\r\n");
		messagesString.add(model.getFirstEntityL() + ".delete="
				+ model.getEntityP() + " Delete\r\n");
		messagesString.add(model.getFirstEntityL()
				+ ".createUser=Create User\r\n");
		messagesString.add(model.getFirstEntityL()
				+ ".createDate=Create Date\r\n");
		for (Field field : fields) {
			//
			if (field == null) {
				break;
			}
//			System.out.println("entity >>>>>>>>>>> " + field.getName());
			messagesString.add(model.getFirstEntityL() + "."
					+ field.getName() + "=" + field.getName() + " \r\n");
		}
		for (String string : messagesString) {
			System.out.print(string);
		}
	}
	public String getPagePath(String name) {
		StringBuilder sb = new StringBuilder();
		sb.append("content/WEB-INF/jsp/");
		// File file =new File(sb.toString());
		sb.append(model.getEntityL());
		// file =new File(sb.toString());
		// if(!file.exists()){
		// file.mkdir();
		// }
		sb.append("/");
		sb.append(model.getFirstEntityL());
		// file =new File(sb.toString());
		// if(!file.exists()){
		// file.mkdir();
		// }
		sb.append("/");
		sb.append(name);
		// file =new File(sb.toString());
		return sb.toString();
	}
	abstract void product();
}
